haptic5 2.2.0
Loading...
Searching...
No Matches
haptic5.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef HAPTIC5_H
29#define HAPTIC5_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52#include "drv_pwm.h"
53
59
64
69
74#define HAPTIC5_REG_PRODUCT_NUM 0x0000
75#define HAPTIC5_REG_MAJOR_VER 0x0002
76#define HAPTIC5_REG_MINOR_VER 0x0004
77#define HAPTIC5_REG_SYSTEM_STATUS 0x1000
78#define HAPTIC5_REG_SYSTEM_SETTINGS 0x1002
79#define HAPTIC5_REG_OVER_TEMP_SETTINGS 0x1003
80#define HAPTIC5_REG_CONT_MODE_REP_TIME 0x1004
81#define HAPTIC5_REG_SYSTEM_CONTROL 0x1006
82#define HAPTIC5_REG_HAPTIC_CONTROL 0x1007
83#define HAPTIC5_REG_HBRIDGE_SETUP 0x2000
84#define HAPTIC5_REG_PWM_FREQUENCY 0x20A0
85#define HAPTIC5_REG_LRA_FREQUENCY 0x20A2
86#define HAPTIC5_REG_AUTORESONANCE_BOFF 0x20A4
87 // haptic5_reg
89
94
99
104#define HAPTIC5_COM_PWM 0
105#define HAPTIC5_COM_I2C 1
106#define HAPTIC5_DEFAULT_COM HAPTIC5_COM_PWM
107
112#define HAPTIC5_PRODUCT_NUM 0x09B9
113
118#define HAPTIC5_SYSTEM_SETTINGS_MODE_NORMAL 0x00
119#define HAPTIC5_SYSTEM_SETTINGS_MODE_CONTINUOUS 0x80
120#define HAPTIC5_SYSTEM_SETTINGS_MODE_MASK 0x80
121#define HAPTIC5_SYSTEM_SETTINGS_TRIGGER_EDGE 0x00
122#define HAPTIC5_SYSTEM_SETTINGS_TRIGGER_LEVEL 0x40
123#define HAPTIC5_SYSTEM_SETTINGS_TRIGGER_MASK 0x40
124#define HAPTIC5_SYSTEM_SETTINGS_TIMEOUT_0MS 0x00
125#define HAPTIC5_SYSTEM_SETTINGS_TIMEOUT_512MS 0x04
126#define HAPTIC5_SYSTEM_SETTINGS_TIMEOUT_1024MS 0x08
127#define HAPTIC5_SYSTEM_SETTINGS_TIMEOUT_1536MS 0x0C
128#define HAPTIC5_SYSTEM_SETTINGS_TIMEOUT_2048MS 0x10
129#define HAPTIC5_SYSTEM_SETTINGS_TIMEOUT_2560MS 0x14
130#define HAPTIC5_SYSTEM_SETTINGS_TIMEOUT_3072MS 0x18
131#define HAPTIC5_SYSTEM_SETTINGS_TIMEOUT_3584MS 0x1C
132#define HAPTIC5_SYSTEM_SETTINGS_TIMEOUT_4096MS 0x20
133#define HAPTIC5_SYSTEM_SETTINGS_TIMEOUT_4608MS 0x24
134#define HAPTIC5_SYSTEM_SETTINGS_TIMEOUT_5120MS 0x28
135#define HAPTIC5_SYSTEM_SETTINGS_TIMEOUT_5632MS 0x2C
136#define HAPTIC5_SYSTEM_SETTINGS_TIMEOUT_6144MS 0x30
137#define HAPTIC5_SYSTEM_SETTINGS_TIMEOUT_6656MS 0x34
138#define HAPTIC5_SYSTEM_SETTINGS_TIMEOUT_7168MS 0x38
139#define HAPTIC5_SYSTEM_SETTINGS_TIMEOUT_7680MS 0x3C
140#define HAPTIC5_SYSTEM_SETTINGS_TIMEOUT_MASK 0x3C
141#define HAPTIC5_SYSTEM_SETTINGS_PWR_MODE_FAST 0x00
142#define HAPTIC5_SYSTEM_SETTINGS_PWR_MODE_ULP 0x01
143#define HAPTIC5_SYSTEM_SETTINGS_PWR_MODE_AUTO 0x02
144#define HAPTIC5_SYSTEM_SETTINGS_PWR_MODE_MASK 0x03
145
150#define HAPTIC5_SYSTEM_CONTROL_SOFT_RESET 0x02
151#define HAPTIC5_SYSTEM_CONTROL_ACK_RESET 0x01
152
157#define HAPTIC5_PWM_DEF_FREQ 20000
158#define HAPTIC5_PWM_DEF_DUTY 0.0
159
165#define HAPTIC5_DEVICE_ADDRESS_0 0x54
166#define HAPTIC5_DEVICE_ADDRESS_1 0x40
167#define HAPTIC5_DEVICE_ADDRESS_0_DEBUG 0x55
168#define HAPTIC5_DEVICE_ADDRESS_1_DEBUG 0x41
169 // haptic5_set
171
176
181
186#define HAPTIC5_MAP_MIKROBUS( cfg, mikrobus ) \
187 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
188 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
189 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
190 cfg.trg = MIKROBUS( mikrobus, MIKROBUS_AN ); \
191 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
192 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_CS );
193 // haptic5_map // haptic5
196
201typedef struct
202{
203 // Output pins
204 digital_out_t trg;
205 digital_out_t rst;
206 digital_out_t dir;
207
208 // Modules
209 pwm_t pwm;
210 i2c_master_t i2c;
211
212 // PWM frequency
213 uint32_t pwm_freq;
214
215 // I2C slave address
217
218} haptic5_t;
219
224typedef struct
225{
226 // Communication gpio pins
227 pin_name_t scl;
228 pin_name_t sda;
229 pin_name_t pwm;
230
231 // Additional gpio pins
232 pin_name_t trg;
233 pin_name_t rst;
234 pin_name_t dir;
235
236 // Static variable
237 uint32_t dev_pwm_freq;
238 uint32_t i2c_speed;
239 uint8_t i2c_address;
240
242
247typedef enum
248{
251
253
259
270
285
299
300#if ( HAPTIC5_DEFAULT_COM == HAPTIC5_COM_I2C )
301
314err_t haptic5_write_regs ( haptic5_t *ctx, uint16_t reg, uint8_t *data_in, uint8_t len );
315
328err_t haptic5_read_regs ( haptic5_t *ctx, uint16_t reg, uint8_t *data_out, uint8_t len );
329
341err_t haptic5_write_reg_byte ( haptic5_t *ctx, uint16_t reg, uint8_t data_in );
342
354err_t haptic5_read_reg_byte ( haptic5_t *ctx, uint16_t reg, uint8_t *data_out );
355
367err_t haptic5_write_reg_word ( haptic5_t *ctx, uint16_t reg, uint16_t data_in );
368
380err_t haptic5_read_reg_word ( haptic5_t *ctx, uint16_t reg, uint16_t *data_out );
381
391err_t haptic5_check_communication ( haptic5_t *ctx );
392
401void haptic5_set_trg_low ( haptic5_t *ctx );
402
411void haptic5_set_trg_high ( haptic5_t *ctx );
412
413#else
414
425err_t haptic5_set_duty_cycle ( haptic5_t *ctx, float duty_cycle );
426
437
448
458
468
478
479#endif
480
490
500
501#ifdef __cplusplus
502}
503#endif
504#endif // HAPTIC5_H
505 // haptic5
507
508// ------------------------------------------------------------------------ END
void haptic5_disable_device(haptic5_t *ctx)
Haptic 5 disable device function.
void haptic5_toggle_dir(haptic5_t *ctx)
Haptic 5 toggle direction function.
void haptic5_set_dir_forward(haptic5_t *ctx)
Haptic 5 set direction forward function.
err_t haptic5_init(haptic5_t *ctx, haptic5_cfg_t *cfg)
Haptic 5 initialization function.
void haptic5_enable_device(haptic5_t *ctx)
Haptic 5 enable device function.
err_t haptic5_pwm_stop(haptic5_t *ctx)
Haptic 5 stop PWM function.
void haptic5_cfg_setup(haptic5_cfg_t *cfg)
Haptic 5 configuration object setup function.
void haptic5_set_dir_reverse(haptic5_t *ctx)
Haptic 5 set direction reverse function.
err_t haptic5_pwm_start(haptic5_t *ctx)
Haptic 5 start PWM function.
err_t haptic5_default_cfg(haptic5_t *ctx)
Haptic 5 default configuration function.
err_t haptic5_set_duty_cycle(haptic5_t *ctx, float duty_cycle)
Haptic 5 set duty cycle function.
haptic5_return_value_t
Haptic 5 Click return value data.
Definition haptic5.h:248
@ HAPTIC5_OK
Definition haptic5.h:249
@ HAPTIC5_ERROR
Definition haptic5.h:250
Haptic 5 Click configuration object.
Definition haptic5.h:225
uint32_t i2c_speed
Definition haptic5.h:238
uint32_t dev_pwm_freq
Definition haptic5.h:237
pin_name_t dir
Definition haptic5.h:234
pin_name_t scl
Definition haptic5.h:227
pin_name_t trg
Definition haptic5.h:232
pin_name_t pwm
Definition haptic5.h:229
pin_name_t sda
Definition haptic5.h:228
pin_name_t rst
Definition haptic5.h:233
uint8_t i2c_address
Definition haptic5.h:239
Haptic 5 Click context object.
Definition haptic5.h:202
digital_out_t trg
Definition haptic5.h:204
uint32_t pwm_freq
Definition haptic5.h:213
i2c_master_t i2c
Definition haptic5.h:210
digital_out_t rst
Definition haptic5.h:205
uint8_t slave_address
Definition haptic5.h:216
pwm_t pwm
Definition haptic5.h:209
digital_out_t dir
Definition haptic5.h:206